package top.yuki.board;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Score;
import org.bukkit.scoreboard.Scoreboard;
import top.yuki.LevelWorld;
import top.yuki.data.DataManager;
import top.yuki.data.WorldManage;

public class PlayerBoard {

    private Scoreboard s = Bukkit.getScoreboardManager().getNewScoreboard();
    private Objective o = s.registerNewObjective("PlayerBoard", "PlayerBoard");
    private Player p = null;
    private static LevelWorld lw ;
    private static DataManager dataManage;
    private static WorldManage worldManage;
    public PlayerBoard(Player p) {

        o.setDisplaySlot(DisplaySlot.SIDEBAR);
        p.setScoreboard(s);
        this.p=p;
        lw = LevelWorld.instance;
        dataManage = lw.dataManage;
        worldManage = lw.worldManage;

    }

    public boolean show(){
        o.setDisplayName(ChatColor.YELLOW+"幻樱之城");
        o.getScore("Lv:").setScore(dataManage.getLevel(p.getUniqueId()));
        o.getScore("精华:").setScore(dataManage.getEssence(p.getUniqueId()));
        o.getScore("精华上限:").setScore(dataManage.calMaxEssence(p.getUniqueId()));
        o.getScore("所需经验:").setScore(dataManage.calMaxXp(p.getUniqueId())-dataManage.getXp(p.getUniqueId()));
        o.getScore("经验:").setScore(dataManage.getXp(p.getUniqueId()));
        o.getScore("当前世界:").setScore(worldManage.getWorldLevel(p.getWorld().getName()));
        o.getScore("世界等级:").setScore(dataManage.getWorldLevel(p.getUniqueId()));

        return true;
    }

    public static boolean refresh(Player p){

        Score text;

        text = p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore("Lv:");
        text.setScore(dataManage.getLevel(p.getUniqueId()));

        text = p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore("精华:");
        text.setScore(dataManage.getEssence(p.getUniqueId()));

        text = p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore("精华上限:");
        text.setScore(dataManage.calMaxEssence(p.getUniqueId()));

        text = p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore("所需经验:");
        text.setScore(dataManage.calMaxXp(p.getUniqueId())-dataManage.getXp(p.getUniqueId()));

        text = p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore("当前世界:");
        text.setScore(worldManage.getWorldLevel(p.getWorld().getName()));

        text = p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore("经验:");
        text.setScore(dataManage.getXp(p.getUniqueId()));

        text = p.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getScore("世界等级:");
        text.setScore(dataManage.getWorldLevel(p.getUniqueId()));
        return true;
    }


    public boolean change( ){

        return true;

    }
}
